<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
          <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="1000px">
        <el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="120px">
          <h2>化学品信息</h2>
          <el-form-item label="化学品中文名称" prop="chemicalsCn">
            <el-input v-model="form.chemicalsCn" />
          </el-form-item>
          <el-form-item label="化学品英文名称">
            <el-input v-model="form.chemicalsEn" />
          </el-form-item>
          <el-form-item label="化学品别名">
            <el-input v-model="form.chemicalsAlias" />
          </el-form-item>
          <el-form-item label="cas">
            <el-input v-model="form.chemicalsCas" />
          </el-form-item>
          <el-form-item label="化学品类别">
            <!--<el-input v-model="form.deviceType" style="width: 370px;" />-->
            <el-select v-model="form.chemicalsType" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.chemicla_type"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <!---->
          <!--<el-form-item label="化学品类别" prop="chemicalsType">-->
          <!--<el-input v-model="form.chemicalsType" />-->
          <!--</el-form-item>-->
          <el-form-item label="化学品文件">
            <el-input v-model="form.chemicalsMsds" />
          </el-form-item>
          <h2>供应商信息</h2>
          <el-form-item label="供应商名称" prop="supplierName">
            <el-input v-model="form.supplierName" />
          </el-form-item>
          <el-form-item label="供应商联系人" prop="supplierContactName">
            <el-input v-model="form.supplierContactName" />
          </el-form-item>
          <el-form-item label="供应商联系方式" prop="supplierContactPhone">
            <el-input v-model="form.supplierContactPhone" />
          </el-form-item>
          <h2>应急咨询</h2>
          <el-form-item label="咨询单位名称" prop="emConsultantName">
            <el-input v-model="form.emConsultantName" />
          </el-form-item>
          <el-form-item label="应急联系人" prop="emContactName">
            <el-input v-model="form.emContactName" />
          </el-form-item>
          <el-form-item label="应急联系方式" prop="emContactPhone">
            <el-input v-model="form.emContactPhone" />
          </el-form-item>
          <h2>仓储信息</h2>
          <el-form-item label="仓库区域">
            <el-select v-model="form.storageArea" placeholder="请选择" style="width: 370px">
              <el-option v-for="item in areas" :key="item.id" :label="item.areaName" :value="item.id" />
            </el-select>
          </el-form-item>

          <el-form-item label="使用区域">
            <el-select v-model="form.useArea" placeholder="请选择" style="width: 370px">
              <el-option v-for="item in areas" :key="item.id" :label="item.areaName" :value="item.id" />
            </el-select>
          </el-form-item>

          <!--<el-form-item label="仓库区域" prop="storageArea">-->
          <!--<el-input v-model="form.storageArea" />-->
          <!--</el-form-item>-->
          <!--<el-form-item label="使用区域" prop="useArea">-->
          <!--<el-input v-model="form.useArea" />-->
          <!--</el-form-item>-->
          <h2>危害信息</h2>

          <el-form-item label="是否是危险品" prop="isDangerousGood">
            <!--<el-input v-model="form.isDangerousGood" />-->

            <el-radio-group v-model="form.isDangerousGood" style="width: 178px">
              <el-radio label="是">是</el-radio>
              <el-radio label="否">否</el-radio>

            </el-radio-group>

          </el-form-item>

          <el-form-item label="危险类型" prop="dangerousCategory">
            <el-input v-model="form.dangerousCategory" />
          </el-form-item>
          <el-form-item label="登记号" prop="registrationNo">
            <el-input v-model="form.registrationNo" />
          </el-form-item>
          <el-form-item label="包装类别" prop="packingCategory">
            <el-input v-model="form.packingCategory" />
          </el-form-item>
          <el-form-item label="危险特性">
            <el-input v-model="form.hazardCharacteristics" :rows="3" type="textarea" />
          </el-form-item>
          <el-form-item label="活性危害">
            <el-input v-model="form.activeHazard" :rows="3" type="textarea" />
          </el-form-item>
          <el-form-item label="预防及应急措施">
            <el-input v-model="form.prevention" :rows="3" type="textarea" />
          </el-form-item>
          <el-form-item label="危规号" prop="hazardNo">
            <el-input v-model="form.hazardNo" />
          </el-form-item>
          <el-form-item label="禁配物">
            <el-input v-model="form.incompatibility" :rows="3" type="textarea" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="chemicalsCn" label="化学品中文名称" />
        <el-table-column prop="chemicalsEn" label="化学品英文名称" />
        <el-table-column prop="chemicalsAlias" label="化学品别名" />
        <el-table-column prop="chemicalsCas" label="cas" />
        <el-table-column prop="chemicalsType" label="化学品类别">
          <template slot-scope="scope">
            {{ dict.label.chemicla_type[scope.row.chemicalsType] }}
          </template>
        </el-table-column>
        <!--<el-table-column prop="chemicalsMsds" label="化学品文件" />-->
        <!--<el-table-column prop="supplierName" label="供应商名称" />-->
        <!--<el-table-column prop="supplierContactName" label="供应商联系人" />-->
        <!--<el-table-column prop="supplierContactPhone" label="供应商联系方式" />-->
        <!--<el-table-column prop="emConsultantName" label="咨询单位名称" />-->
        <!--<el-table-column prop="emContactName" label="应急联系人" />-->
        <!--<el-table-column prop="emContactPhone" label="应急联系方式" />-->
        <!--<el-table-column prop="storageArea" label="仓库区域" />-->
        <el-table-column prop="useAreaName" label="使用区域" />
        <el-table-column prop="isDangerousGood" label="是否是危险品" />
        <!--<el-table-column prop="dangerousCategory" label="危险类型" />-->
        <!--<el-table-column prop="registrationNo" label="登记号" />-->
        <!--<el-table-column prop="packingCategory" label="包装类别" />-->
        <!--<el-table-column prop="hazardCharacteristics" label="危险特性" />-->
        <!--<el-table-column prop="activeHazard" label="活性危害" />-->
        <!--<el-table-column prop="prevention" label="预防及应急措施-->
        <!--" />-->
        <!--<el-table-column prop="hazardNo" label="危规号" />-->
        <!--<el-table-column prop="incompatibility" label="禁配物" />-->
        <el-table-column v-permission="['admin','chemicla:edit','chemicla:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudChemicla from '@/api/psp/chemicla/chemicla'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import crudAreas from '@/api/system/areaManage'

const defaultForm = { id: null, createTime: null, updateTime: null, createBy: null, updateBy: null, chemicalsCn: null, chemicalsEn: null, chemicalsAlias: null, chemicalsCas: null, chemicalsType: null, chemicalsMsds: null, supplierName: null, supplierContactName: null, supplierContactPhone: null, emConsultantName: null, emContactName: null, emContactPhone: null, storageArea: null, useArea: null, isDangerousGood: '是', dangerousCategory: null, registrationNo: null, packingCategory: null, hazardCharacteristics: null, activeHazard: null, prevention: null, hazardNo: null, incompatibility: null }
export default {
  name: 'Chemicla',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['chemicla_type'],
  cruds() {
    return CRUD({ title: '化学品管理', url: 'api/chemicla', sort: 'id,desc', crudMethod: { ...crudChemicla }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'chemicla:add'],
        edit: ['admin', 'chemicla:edit'],
        del: ['admin', 'chemicla:del']
      },
      areas: [],
      rules: {

        chemicalsCn: [
          { required: true, message: '化学品中文名称不能为空', trigger: 'blur' }
          // ]
          // chemicalsType: [
          //   { required: true, message: '化学品类别不能为空', trigger: 'blur' }
          // ],
          // supplierName: [
          //   { required: true, message: '供应商名称不能为空', trigger: 'blur' }
          // ],
          // supplierContactName: [
          //   { required: true, message: '供应商联系人不能为空', trigger: 'blur' }
          // ],
          // supplierContactPhone: [
          //   { required: true, message: '供应商联系方式不能为空', trigger: 'blur' }
          // ],
          // emConsultantName: [
          //   { required: true, message: '咨询单位名称不能为空', trigger: 'blur' }
          // ],
          // emContactName: [
          //   { required: true, message: '应急联系人不能为空', trigger: 'blur' }
          // ],
          // emContactPhone: [
          //   { required: true, message: '应急联系方式不能为空', trigger: 'blur' }
          // ],
          // storageArea: [
          //   { required: true, message: '仓库区域不能为空', trigger: 'blur' }
          // ],
          // useArea: [
          //   { required: true, message: '使用区域不能为空', trigger: 'blur' }
          // ],
          // isDangerousGood: [
          //   { required: true, message: '是否是危险品不能为空', trigger: 'blur' }
          // ],
          // dangerousCategory: [
          //   { required: true, message: '危险类型不能为空', trigger: 'blur' }
          // ],
          // registrationNo: [
          //   { required: true, message: '登记号不能为空', trigger: 'blur' }
          // ],
          // packingCategory: [
          //   { required: true, message: '包装类别不能为空', trigger: 'blur' }
          // ],
          // hazardNo: [
          //   { required: true, message: '危规号不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'chemicalsCn', display_name: '化学品中文名称' },
        { key: 'chemicalsEn', display_name: '化学品英文名称' },
        { key: 'chemicalsAlias', display_name: '化学品别名' },
        { key: 'chemicalsType', display_name: '化学品类别' },
        { key: 'storageArea', display_name: '仓库区域' },
        { key: 'isDangerousGood', display_name: '是否是危险品' },
        { key: 'dangerousCategory', display_name: '危险类型' },
        { key: 'registrationNo', display_name: '登记号' },
        { key: 'packingCategory', display_name: '包装类别' },
        { key: 'hazardNo', display_name: '危规号' }
      ]
    }
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      this.initSelect()
      const query = this.query
      if (query.type && query.value) {
        this.crud.params[query.type] = query.value
      }
      return true
    },
    initSelect() {
      crudAreas.getAreaList().then(res => {
        console.log(res)
        this.areas = res.content
      })
    }
  }
}
</script>

<style scoped>

</style>
